package com.mall.b2c.bean;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

import org.springframework.util.CollectionUtils;

import com.google.common.collect.Lists;
import com.mall.b2c.domain.delivery.DeliveryMethodDomain;
import com.mall.b2c.domain.order.OrderDomain;
import com.mall.b2c.domain.order.OrderItemDomain;
import com.mall.common.util.BeanUtils;

public class OrderBean {
	
	private Long id;
	private String orderNo;//订单编号
	private BigDecimal totalAmount;//下单时订单金额
	private String feeDate;// 付款日期
	private BigDecimal shipFee;//快递费
	private BigDecimal deposit;//使用余额
	private BigDecimal cash;//使用现金

	private Boolean isDelete;//是否删除
	private Boolean isExpired;//过期时间
	private String lockExpired;//后台订单操作锁定过期时间
	
	private String payStatus;//付款状态
	private String shipStatus;//发货状态
	private String orderStatus;// 订单状态

	private String payType;//支付类型
	private String tradeNo;//支付编号
	private String postscript;//附言
	
	private String logisticsNo;// 物流单号
	private Boolean isInvoice;// 是否开票
	private Integer invoiceType;// 发票类型：1.个人 2.单位
	private String invoiceTitle;//发票抬头
	private String consignee; //收货人
	private Long areaId; //收货地区ID
	private String areaName; //收货人地区
	private String address;// 收货人地址
	private String contact;// 收货人联系方式
	private String zipCode;// 收货人邮编
	
	private Long deliveryMethodId; //配送方式
	private String deliveryMethodName; //配送方式名称
	private String deliveryCorp; //物流公司
	private MemberBean memberBean; //会员
	private Long paymentTypeId; //支付方式id
	private String paymentTypeName;//支付方式名称

	private Boolean hasRefunded; //是否退款
	private String createDate; //下单时间
	
	private List<OrderItemBean> items;
	
	public OrderBean(OrderDomain order){
		this(order, true);
	}

	public OrderBean(OrderDomain order, boolean withItems){
		
		BeanUtils.copyProperties(order, this);
		
		DeliveryMethodDomain deliveryMethod =  order.getDeliveryMethod();
		if(deliveryMethod != null){
			setDeliveryMethodId(deliveryMethod.getId());
			setDeliveryMethodName(deliveryMethod.getName());
			setDeliveryCorp(deliveryMethod.getCompany());
		}
		
		setMemberBean(new MemberBean(order.getMember()));
		
		if(withItems){
			Set<OrderItemDomain> itemSet = order.getOrderItems();
			if(!CollectionUtils.isEmpty(itemSet)){
				items = Lists.newLinkedList();
				for(OrderItemDomain item : itemSet){
					items.add(new OrderItemBean(item));
				}
			}
		}
	}

	public String getDeliveryCorp() {
		return deliveryCorp;
	}

	public void setDeliveryCorp(String deliveryCorp) {
		this.deliveryCorp = deliveryCorp;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = totalAmount;
	}

	public String getFeeDate() {
		return feeDate;
	}

	public void setFeeDate(String feeDate) {
		this.feeDate = feeDate;
	}

	public BigDecimal getShipFee() {
		return shipFee;
	}

	public void setShipFee(BigDecimal shipFee) {
		this.shipFee = shipFee;
	}

	public BigDecimal getDeposit() {
		return deposit;
	}

	public void setDeposit(BigDecimal deposit) {
		this.deposit = deposit;
	}

	public BigDecimal getCash() {
		return cash;
	}

	public void setCash(BigDecimal cash) {
		this.cash = cash;
	}

	public Boolean getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(Boolean isDelete) {
		this.isDelete = isDelete;
	}

	public Boolean getIsExpired() {
		return isExpired;
	}

	public void setIsExpired(Boolean isExpired) {
		this.isExpired = isExpired;
	}

	public String getLockExpired() {
		return lockExpired;
	}

	public void setLockExpired(String lockExpired) {
		this.lockExpired = lockExpired;
	}

	public String getPayStatus() {
		return payStatus;
	}

	public void setPayStatus(String payStatus) {
		this.payStatus = payStatus;
	}

	public String getShipStatus() {
		return shipStatus;
	}

	public void setShipStatus(String shipStatus) {
		this.shipStatus = shipStatus;
	}

	public String getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}

	public String getPayType() {
		return payType;
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}

	public String getTradeNo() {
		return tradeNo;
	}

	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}

	public String getPostscript() {
		return postscript;
	}

	public void setPostscript(String postscript) {
		this.postscript = postscript;
	}

	public String getLogisticsNo() {
		return logisticsNo;
	}

	public void setLogisticsNo(String logisticsNo) {
		this.logisticsNo = logisticsNo;
	}

	public Boolean getIsInvoice() {
		return isInvoice;
	}

	public void setIsInvoice(Boolean isInvoice) {
		this.isInvoice = isInvoice;
	}

	public Integer getInvoiceType() {
		return invoiceType;
	}

	public void setInvoiceType(Integer invoiceType) {
		this.invoiceType = invoiceType;
	}

	public String getInvoiceTitle() {
		return invoiceTitle;
	}

	public void setInvoiceTitle(String invoiceTitle) {
		this.invoiceTitle = invoiceTitle;
	}

	public String getConsignee() {
		return consignee;
	}

	public void setConsignee(String consignee) {
		this.consignee = consignee;
	}

	public Long getAreaId() {
		return areaId;
	}

	public void setAreaId(Long areaId) {
		this.areaId = areaId;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public Long getDeliveryMethodId() {
		return deliveryMethodId;
	}

	public void setDeliveryMethodId(Long deliveryMethodId) {
		this.deliveryMethodId = deliveryMethodId;
	}
	
	public String getDeliveryMethodName() {
		return deliveryMethodName;
	}

	public void setDeliveryMethodName(String deliveryMethodName) {
		this.deliveryMethodName = deliveryMethodName;
	}

	public MemberBean getMemberBean() {
		return memberBean;
	}

	public void setMemberBean(MemberBean memberBean) {
		this.memberBean = memberBean;
	}

	public Long getPaymentTypeId() {
		return paymentTypeId;
	}

	public void setPaymentTypeId(Long paymentTypeId) {
		this.paymentTypeId = paymentTypeId;
	}

	public String getPaymentTypeName() {
		return paymentTypeName;
	}

	public void setPaymentTypeName(String paymentTypeName) {
		this.paymentTypeName = paymentTypeName;
	}
	
	public List<OrderItemBean> getItems() {
		return items;
	}

	public void setItems(List<OrderItemBean> items) {
		this.items = items;
	}
	
	public String getCreateDate() {
		return createDate;
	}
	
	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public Boolean getHasRefunded() {
		return hasRefunded;
	}

	public void setHasRefunded(Boolean hasRefunded) {
		this.hasRefunded = hasRefunded;
	}
}
